from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime

# 新增ProductImage相关schema
class ProductImageBase(BaseModel):
    filename: str
    original_filename: str
    file_path: str
    file_size: int
    content_type: str
    product_id: Optional[int] = None

class ProductImageCreate(ProductImageBase):
    pass

class ProductImageUpdate(BaseModel):
    product_id: Optional[int] = None

class ProductImage(ProductImageBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True

# 现有的Product相关schema保持不变
class ProductBase(BaseModel):
    name: str
    price: float
    description: Optional[str] = None
    category_id: int
    is_active: bool = True

class ProductCreate(ProductBase):
    pass

class ProductUpdate(BaseModel):
    name: Optional[str] = None
    price: Optional[float] = None
    description: Optional[str] = None
    category_id: Optional[int] = None
    is_active: Optional[bool] = None

class Product(ProductBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None
    category_name: Optional[str] = None
    images: List[ProductImage] = []
    first_image_url: Optional[str] = None

    class Config:
        from_attributes = True

# 分页响应模型
class ProductListResponse(BaseModel):
    items: List[Product]
    total: int
    page: int
    page_size: int
    total_pages: int

# 现有的Category相关schema保持不变
class CategoryBase(BaseModel):
    name: str
    description: Optional[str] = None
    is_active: bool = True

class CategoryCreate(CategoryBase):
    pass

class CategoryUpdate(BaseModel):
    name: Optional[str] = None
    description: Optional[str] = None
    is_active: Optional[bool] = None

class Category(CategoryBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True

# 现有的ProductDetail相关schema保持不变
class ProductDetailBase(BaseModel):
    rich_content: Optional[str] = None
    specifications: Optional[str] = None
    features: Optional[str] = None

class ProductDetailCreate(ProductDetailBase):
    pass

class ProductDetailUpdate(BaseModel):
    rich_content: Optional[str] = None
    specifications: Optional[str] = None
    features: Optional[str] = None

class ProductDetail(ProductDetailBase):
    id: int
    product_id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True 